$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

/**
 * 保存提交
 */
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : ctxPath +  "dept/addDept",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function (request) {
			parent.layer.msg("操作失败");
		},
		success : function(data) {
			if (data.code == 200) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);
			} else {
				if(data.msg == "" || data.msg == null)
				{
					parent.layer.msg("操作失败！")
				}
				else
				{
					parent.layer.alert(data.msg)
				}
			}
		}
	});
}

/**
 * 关闭窗口
 */
function fclose() {
	var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
	parent.layer.close(index);
}

/**
 * from验证
 */
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			},
			simplename:{
				required : true
			},
			fullname:{
				required : true
			},
			deptName:{
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入姓名"
			},
			simplename:{
				required : icon + "请完善简称"
			},
			fullname:{
				required : icon + "请完善全称"
			},
			deptName:{
				required : icon + "请选择上级部门"
			}
		}
	})
}

/**
 * 选择部门弹出框
 */
var openDept = function(){
	layer.open({
		type:2,
		title:"选择部门",
		area : [ '300px', '320px' ],
		content: ctxPath +  "user/deptTreeView"
	})
}

/**
 * 选择部门弹出框选择数据显示
 */
function loadDept( deptId,deptName){
	$("#pid").val(deptId);
	$("#deptName").val(deptName);
}